package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.AttendanceRequestDTO;
import com.tianya.domain.entity.Attendance;
import com.tianya.domain.vo.AttendanceVO;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.service.AttendanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author TianYaGuoKe
 * @date 2025/5/26 13:26
 * @description AttendanceController
 */
@Api("考勤管理")
@RestController
@RequestMapping("/attendance")
public class AttendanceController {
    @Resource
    private AttendanceService attendanceService;

    @ApiOperation("创建考勤")
    @PostMapping
    public Results createAttendance(@RequestBody AttendanceRequestDTO attendanceRequestDTO) {
        attendanceService.createAttendance(attendanceRequestDTO);
        return Results.success();
    }
    @ApiOperation("根据学生id查询考勤")
    @GetMapping("/student/{id}")
    public Results<AttendanceVO> getAttendanceByStudId(@PathVariable Long id) {
        return Results.success(attendanceService.getAttendanceByStuId(id));
    }
    @ApiOperation("分页获取考勤")
    @PostMapping("/page")
    public Results<PageResultVO<AttendanceVO>> pageAttendance(@RequestParam(defaultValue = "1") Integer pageNum,
                                                              @RequestParam(defaultValue = "10") Integer pageSize,
                                                              AttendanceRequestDTO attendanceRequestDTO) {
        return Results.success(attendanceService.pageAttendance(pageNum, pageSize, attendanceRequestDTO));
    }

    @ApiOperation("查看详情")
    @GetMapping("/{id}")
    public Results<Attendance> getAttendance(@PathVariable Long id) {
        return Results.success(attendanceService.getById(id));
    }

    @ApiOperation("编辑考勤")
    @PutMapping
    public Results updateAttendance(@RequestBody Attendance attendance) {
        attendanceService.updateById(attendance);
        return Results.success();
    }

    @ApiOperation("删除考勤")
    @DeleteMapping("/{id}")
    public Results deleteAttendance(@PathVariable Long id) {
        attendanceService.removeById(id);
        return Results.success();
    }
}
